package o;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.provider.Settings.Global;
import android.provider.Settings.Secure;
import android.view.View;
import android.view.View.OnApplyWindowInsetsListener;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.WindowManager.LayoutParams;
import com.tencent.mm.opensdk.modelmsg.WXMediaMessage;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;

public class ayw {
    private static int ˋ;
    private static int ˎ;
    private static int ˏ;
    private static int ॱ = 0;

    @SuppressLint({"NewApi"})
    public static final class c implements OnApplyWindowInsetsListener {
        private boolean ˊ;
        private Activity ˋ;

        public c(Activity activity, boolean z) {
            this.ˊ = z;
            this.ˋ = activity;
        }

        public WindowInsets onApplyWindowInsets(View view, WindowInsets windowInsets) {
            if (ayw.ˏ(windowInsets, this.ˋ) == null) {
                return windowInsets.consumeStableInsets();
            }
            ayw.ˋ = ayw.ʼ(windowInsets, this.ˋ);
            ayw.ˎ = ayw.ʽ(windowInsets, this.ˋ);
            ayw.ˏ = ayw.ॱॱ(windowInsets, this.ˋ);
            ayv.ˎ.ˎ("CutoutUtils", "onApplyWindowInsets , Left: " + ayw.ˋ + ", Right:" + ayw.ˎ + ", Top:" + ayw.ˏ);
            if (this.ˊ) {
                ayw.ॱ(this.ˋ, view, ayw.ˋ, ayw.ˏ, ayw.ˎ);
            } else {
                ayw.ˎ(this.ˋ, view, ayw.ˋ, ayw.ˏ, ayw.ˎ);
            }
            return windowInsets.consumeStableInsets();
        }
    }

    @SuppressLint({"NewApi"})
    public static void ˊ(Window window) {
        if (window != null && azc.ˎ().ॱ() >= 17) {
            LayoutParams attributes = window.getAttributes();
            try {
                Class cls = Class.forName("com.huawei.android.view.LayoutParamsEx");
                Object newInstance = cls.getConstructor(new Class[]{LayoutParams.class}).newInstance(new Object[]{attributes});
                cls.getMethod("addHwFlags", new Class[]{Integer.TYPE}).invoke(newInstance, new Object[]{Integer.valueOf(WXMediaMessage.THUMB_LENGTH_LIMIT)});
            } catch (ClassNotFoundException e) {
                ayv.ˎ.ˋ("CutoutUtils", "can not find hwFlags");
            } catch (NoSuchMethodException e2) {
                ayv.ˎ.ˋ("CutoutUtils", "can not find hwFlags");
            } catch (IllegalAccessException e3) {
                ayv.ˎ.ˋ("CutoutUtils", "can not find hwFlags");
            } catch (InstantiationException e4) {
                ayv.ˎ.ˋ("CutoutUtils", "can not find hwFlags");
            } catch (InvocationTargetException e5) {
                ayv.ˎ.ˋ("CutoutUtils", "can not find hwFlags");
            } catch (Exception e6) {
                ayv.ˎ.ˋ("CutoutUtils", "can not find hwFlags");
            }
        }
    }

    public static void ॱ(Activity activity) {
        ˋ(activity, "LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES");
    }

    @SuppressLint({"NewApi"})
    public static void ˏ(Activity activity, int i, View view, boolean z) {
        ArrayList arrayList = new ArrayList();
        if (i != 0) {
            arrayList.add(activity.findViewById(i));
        }
        ॱ(activity, arrayList, view, z);
    }

    @SuppressLint({"NewApi"})
    public static void ˋ(Activity activity, View view, View view2, boolean z) {
        ArrayList arrayList = new ArrayList();
        arrayList.add(view);
        ॱ(activity, arrayList, view2, z);
    }

    @SuppressLint({"NewApi"})
    public static void ॱ(Activity activity, ArrayList<View> arrayList, View view, boolean z) {
        ˎ(activity, arrayList, view, 1280, "LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES", z);
    }

    @SuppressLint({"NewApi", "WrongConstant"})
    public static void ˎ(Activity activity, ArrayList<View> arrayList, View view, int i, String str, boolean z) {
        if (azc.ˎ().ॱ() >= 17) {
            if (Secure.getInt(activity.getContentResolver(), "display_notch_status", 0) != 0) {
                ˋ = 0;
                ˎ = 0;
                ˏ = 0;
                return;
            }
            ˏ(activity, i);
            ˋ(activity, str);
            if (view != null) {
                int ॱ = ॱ((Context) activity);
                ayv.ˎ.ˎ("CutoutUtils", "have title");
                view.setPadding(0, ॱ, 0, 0);
            }
            ayv.ˎ.ˎ("CutoutUtils", "needTopPadding:" + z);
            if (arrayList != null && arrayList.size() > 0) {
                Iterator it = arrayList.iterator();
                while (it.hasNext()) {
                    View view2 = (View) it.next();
                    if (view2 != null) {
                        view2.setOnApplyWindowInsetsListener(new c(activity, z));
                    }
                }
            }
        }
    }

    public static void ˏ(Activity activity, int i) {
        activity.getWindow().getDecorView().setSystemUiVisibility(activity.getWindow().getDecorView().getSystemUiVisibility() | i);
    }

    public static void ˋ(Activity activity, String str) {
        if (azc.ˎ().ॱ() >= 17 && Secure.getInt(activity.getContentResolver(), "display_notch_status", 0) == 0) {
            LayoutParams attributes = activity.getWindow().getAttributes();
            try {
                attributes.getClass().getDeclaredField("layoutInDisplayCutoutMode").set(attributes, Integer.valueOf(attributes.getClass().getDeclaredField(str).getInt(attributes)));
            } catch (Exception e) {
                ayv.ˎ.ˋ("CutoutUtils", "layoutInDisplayCutoutMode" + e.getMessage());
            }
        }
    }

    private static void ॱ(Activity activity, View view, int i, int i2, int i3) {
        ayv.ˎ.ˎ("CutoutUtils", "WithTopPadding");
        view.setPadding(0, 0, 0, 0);
        int rotation = ((WindowManager) activity.getSystemService("window")).getDefaultDisplay().getRotation();
        if (rotation == 1) {
            view.setPadding(i, i, 0, 0);
        } else if (rotation == 3) {
            ॱ = Global.getInt(activity.getContentResolver(), "navigationbar_is_min", 0);
            if (ॱ == 0) {
                view.setPadding(0, i3, 0, 0);
            } else {
                view.setPadding(0, i3, i3, 0);
            }
        } else if (rotation == 0) {
            view.setPadding(0, i2, 0, 0);
        }
    }

    private static void ˎ(Activity activity, View view, int i, int i2, int i3) {
        ayv.ˎ.ˎ("CutoutUtils", "WithoutTopPadding");
        view.setPadding(0, 0, 0, 0);
        int rotation = ((WindowManager) activity.getSystemService("window")).getDefaultDisplay().getRotation();
        if (rotation == 1) {
            view.setPadding(i, 0, 0, 0);
        } else if (rotation == 3) {
            ॱ = Global.getInt(activity.getContentResolver(), "navigationbar_is_min", 0);
            if (ॱ != 0) {
                view.setPadding(0, 0, i3, 0);
            } else {
                view.setPadding(0, 0, 0, 0);
            }
        } else if (rotation == 0) {
            view.setPadding(0, 0, 0, 0);
        }
    }

    private static Object ˏ(WindowInsets windowInsets, Activity activity) {
        try {
            return windowInsets.getClass().getDeclaredMethod("getDisplayCutout", new Class[0]).invoke(windowInsets, new Object[0]);
        } catch (Exception e) {
            ayv.ˎ.ˎ("CutoutUtils", "getDisplayCutout" + e.getMessage());
            return null;
        }
    }

    private static int ʽ(WindowInsets windowInsets, Activity activity) {
        int intValue;
        try {
            ayv.ˎ.ˎ("CutoutUtils", windowInsets.toString());
            Class cls = Class.forName("android.view.DisplayCutout");
            intValue = ((Integer) cls.getDeclaredMethod("getSafeInsetRight", new Class[0]).invoke(windowInsets.getClass().getDeclaredMethod("getDisplayCutout", new Class[0]).invoke(windowInsets, new Object[0]), new Object[0])).intValue();
        } catch (Exception e) {
            Exception exception = e;
            if (3 == ((WindowManager) activity.getSystemService("window")).getDefaultDisplay().getRotation()) {
                intValue = ॱ((Context) activity);
            } else {
                intValue = 0;
            }
            ayv.ˎ.ˎ("CutoutUtils", "getSafeInsetRight" + exception.getMessage());
        }
        return intValue;
    }

    private static int ʼ(WindowInsets windowInsets, Activity activity) {
        int intValue;
        try {
            Class cls = Class.forName("android.view.DisplayCutout");
            intValue = ((Integer) cls.getDeclaredMethod("getSafeInsetLeft", new Class[0]).invoke(windowInsets.getClass().getDeclaredMethod("getDisplayCutout", new Class[0]).invoke(windowInsets, new Object[0]), new Object[0])).intValue();
        } catch (Exception e) {
            Exception exception = e;
            if (1 == ((WindowManager) activity.getSystemService("window")).getDefaultDisplay().getRotation()) {
                intValue = ॱ((Context) activity);
            } else {
                intValue = 0;
            }
            ayv.ˎ.ˎ("CutoutUtils", exception.getMessage());
        }
        return intValue;
    }

    private static int ॱॱ(WindowInsets windowInsets, Activity activity) {
        try {
            return ((Integer) Class.forName("android.view.DisplayCutout").getDeclaredMethod("getSafeInsetTop", new Class[0]).invoke(windowInsets.getClass().getDeclaredMethod("getDisplayCutout", new Class[0]).invoke(windowInsets, new Object[0]), new Object[0])).intValue();
        } catch (Exception e) {
            return ((WindowManager) activity.getSystemService("window")).getDefaultDisplay().getRotation() == 0 ? ॱ((Context) activity) : 0;
        }
    }

    private static int ॱ(Context context) {
        return context.getResources().getDimensionPixelSize(context.getResources().getIdentifier("status_bar_height", "dimen", "android"));
    }
}
